//
//  ViewController.m
//  04-QQHomeWork
//
//  Created by 曹曹 on 16/7/19.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "GX_Button.h"
#import "Masonry.h"

#define SCREEN_WIDTH 414.0f
#define SCREEN_HEIGHT 736.0f

@interface ViewController ()
@property (nonatomic, strong) UIImageView *backgroundView;
@property (nonatomic, strong) AVAudioPlayer *player;
@property (nonatomic, strong) GX_Button *fourButton;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self backgroundImageView];
    [self downpullButton];
    [self upImageView];
    [self topLabel];
    [self songImageView];
    [self playButton];
    [self bottomItem];
}
#pragma mark - 背景
- (void)backgroundImageView {
    _backgroundView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _backgroundView.image = [UIImage imageNamed:@"profile_homepage_default_bg"];
    _backgroundView.alpha = 0.8;
    [self.view addSubview:_backgroundView];
}
#pragma mark - 下拉按钮
- (void)downpullButton {
    GX_Button *downpullButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [downpullButton setImage:[UIImage imageNamed:@"miniplayer_btn_playlist_close"] forState:UIControlStateNormal];
    downpullButton.tintColor = [UIColor whiteColor];
    [self.view addSubview:downpullButton];
    [downpullButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(40);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
}
#pragma mark - 标准,独家,MV,dts
- (void)upImageView {
    GX_Button *button0 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button0 setImage:[[UIImage imageNamed:@"top0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    self.fourButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [self.fourButton setImage:[[UIImage imageNamed:@"top1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button2 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button2 setImage:[[UIImage imageNamed:@"top2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button3 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button3 setImage:[[UIImage imageNamed:@"top3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:button0];
    [self.view addSubview:self.fourButton];
    [self.view addSubview:button2];
    [self.view addSubview:button3];
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view).multipliedBy(1 / 8.0f);
        make.height.mas_equalTo(25);
        make.right.mas_equalTo(self.view.mas_centerX).mas_equalTo(-5);
        make.top.equalTo(self.view).mas_equalTo(130);
    }];
    [button0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view).multipliedBy(1 / 7.0f);
        make.height.centerY.mas_equalTo(self.fourButton);
        make.right.mas_equalTo(self.fourButton.mas_left).mas_equalTo(-10);
    }];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerY.mas_equalTo(self.fourButton);
        make.left.mas_equalTo(self.fourButton.mas_right).mas_equalTo(10);
    }];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.centerY.width.mas_equalTo(self.fourButton);
        make.left.mas_equalTo(button2.mas_right).mas_equalTo(10);
    }];
}
#pragma mark - 歌曲和作者
- (void)topLabel {
    UILabel *songLabel = [UILabel new];
    songLabel.text = @"稻香";
    songLabel.textAlignment = NSTextAlignmentCenter;
    songLabel.textColor = [UIColor whiteColor];
    songLabel.font = [UIFont systemFontOfSize:30];
    UILabel *authorLabel = [UILabel new];
    authorLabel.text = @"周杰伦";
    authorLabel.textAlignment = NSTextAlignmentCenter;
    authorLabel.textColor = [UIColor whiteColor];
    UIView *viewOfLineLeft = [UIView new];
    UIView *viewOfLineRigt = [UIView new];
    viewOfLineLeft.backgroundColor = [UIColor whiteColor];
    viewOfLineRigt.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:songLabel];
    [self.view addSubview:authorLabel];
    [self.view addSubview:viewOfLineLeft];
    [self.view addSubview:viewOfLineRigt];
    [songLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view).multipliedBy(80 / SCREEN_WIDTH);
        make.height.mas_equalTo(self.view).multipliedBy(40 / SCREEN_HEIGHT);
        make.centerY.mas_equalTo(self.view.mas_top).mas_offset(60);
        make.centerX.mas_equalTo(self.view);
    }];
    [authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(self.view).multipliedBy(40 / SCREEN_HEIGHT);
        make.centerY.mas_equalTo(self.view.mas_top).mas_offset(100);
        make.centerX.mas_equalTo(self.view);
    }];
    [viewOfLineLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(authorLabel.mas_left).mas_equalTo(-10);
        make.centerY.mas_equalTo(authorLabel);
    }];
    [viewOfLineRigt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.centerY.mas_equalTo(viewOfLineLeft);
        make.left.mas_equalTo(authorLabel.mas_right).mas_equalTo(10);
    }];
}
#pragma mark - 中间图片
- (void)songImageView {
    UIImageView *backView = [UIImageView new];
    UIImageView *imageView = [UIImageView new];
    backView.image = [UIImage imageNamed:@"player_icon_mvPreview"];
    imageView.image = [UIImage imageNamed:@"songImage"];
    backView.center = imageView.center;
    backView.layer.cornerRadius = 170;
    backView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 160;
    imageView.layer.masksToBounds = YES;
    [self.view addSubview:backView];
    [self.view addSubview:imageView];
    UIPageControl *pageControl = [UIPageControl new];
    pageControl.numberOfPages = 3;
    pageControl.currentPage = 1;
    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [self.view addSubview:pageControl];
    UILabel *label = [UILabel new];
    label.text = @"曲: 周杰伦";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor grayColor];
    [self.view addSubview:label];
    UISlider *slider = [UISlider new];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    [self.view addSubview:slider];
    //创建左边的label
    UILabel *leftLabel = [UILabel new];
    [self.view addSubview:leftLabel];
    leftLabel.textColor = [UIColor whiteColor];
    leftLabel.text = @"00:13";
    //创建右边的label
    UILabel *rightLabel = [UILabel new];
    [self.view addSubview:rightLabel];
    rightLabel.textColor = [UIColor whiteColor];
    rightLabel.text = @"03:13";
    GX_Button *leftButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [leftButton setImage:[[UIImage imageNamed:@"hp_player_btn_pre_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:leftButton];
    GX_Button *midButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [midButton setImage:[[UIImage imageNamed:@"player_btn_pause_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:midButton];
    GX_Button *rightButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [rightButton setImage:[[UIImage imageNamed:@"hp_player_btn_next_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:rightButton];
    GX_Button *vedioButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    [vedioButton setImage:[[UIImage imageNamed:@"player_btn_airplayon_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:vedioButton];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view).multipliedBy(340 / SCREEN_WIDTH);
        make.height.mas_equalTo(self.view.mas_width).multipliedBy(340 / SCREEN_WIDTH);
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.fourButton.mas_bottom).mas_equalTo(10);
    }];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(backView);
        make.width.mas_equalTo(self.view).multipliedBy(320 / SCREEN_WIDTH);
        make.height.mas_equalTo(self.view.mas_width).multipliedBy(320 / SCREEN_WIDTH);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(backView.mas_bottom).mas_equalTo(10);
        make.width.mas_equalTo(self.view).multipliedBy(100);
        make.height.mas_equalTo(30);
    }];
    [pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(label.mas_bottom).mas_equalTo(5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    [slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.view).multipliedBy(300 / SCREEN_WIDTH);
        make.height.mas_equalTo(10);
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(pageControl.mas_bottom).mas_equalTo(8);
    }];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        make.right.mas_equalTo(slider.mas_left).mas_equalTo(0);
        make.centerY.mas_equalTo(slider);
    }];
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerY.mas_equalTo(leftLabel);
        make.left.mas_equalTo(slider.mas_right).mas_equalTo(0);
    }];
    [midButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(slider.mas_bottom).mas_equalTo(10);
        make.width.mas_equalTo(self.view).multipliedBy(100 / SCREEN_WIDTH);
        make.height.mas_equalTo(self.view.mas_width).multipliedBy(100 / SCREEN_WIDTH);
    }];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(midButton);
        make.width.height.mas_equalTo(self.view.mas_width).multipliedBy(90 / SCREEN_WIDTH);
        make.right.mas_equalTo(midButton.mas_left).mas_equalTo(-20);
    }];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(midButton);
        make.width.height.mas_equalTo(leftButton);
        make.left.mas_equalTo(midButton.mas_right).mas_equalTo(20);
    }];
    [vedioButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view).mas_equalTo(-10);
        make.centerY.mas_equalTo(midButton);
        make.width.height.mas_equalTo(self.view.mas_width).multipliedBy(50 / SCREEN_WIDTH);
    }];
}
#pragma mark - playButton
- (void)playButton {
    }
- (void)bottomItem {
    GX_Button *button0 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button0 setImage:[[UIImage imageNamed:@"0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button1 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button1 setImage:[[UIImage imageNamed:@"1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button2 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button2 setImage:[[UIImage imageNamed:@"2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button3 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button3 setImage:[[UIImage imageNamed:@"3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    GX_Button *button4 = [GX_Button buttonWithType:UIButtonTypeSystem];
    [button4 setImage:[[UIImage imageNamed:@"4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:button0];
    [self.view addSubview:button1];
    [self.view addSubview:button2];
    [self.view addSubview:button3];
    [self.view addSubview:button4];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(self.view.mas_width).multipliedBy(35 / SCREEN_WIDTH);
        make.bottom.mas_equalTo(self.view).mas_equalTo(-20);
        make.centerX.mas_equalTo(self.view);
    }];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(button2);
        make.centerY.mas_equalTo(button2);
        make.centerX.mas_equalTo(self.view).multipliedBy(3 / 5.0f);
    }];
    [button0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(button2);
        make.centerY.mas_equalTo(button2);
        make.centerX.mas_equalTo(self.view).multipliedBy(1 / 5.0f);
    }];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(button2);
        make.centerY.mas_equalTo(button2);
        make.centerX.mas_equalTo(self.view).multipliedBy(7 / 5.0f);
    }];
    [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(button2);
        make.centerY.mas_equalTo(button2);
        make.centerX.mas_equalTo(self.view).multipliedBy(9 / 5.0f);
    }];
}
#pragma mark - AVAudioPlayer
- (void)avAudioPlayer {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"歌曲" ofType:@"MP3"];
    NSURL *url = [NSURL fileURLWithPath:path];
    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    // 负数表示无限循环播放, 0表示播放一次, 以此类推
    _player.numberOfLoops = 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
